<!DOCTYPE html>

<html
  xmlns="http://www.w3.org/1999/xhtml"
  >
  <head>
    <title>Network diagram &#8211; from Data to Viz</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="pandoc" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta
      name="description"
      content="An extensive description of Network
diagram. Definition, examples, input data, common caveats, tool to build it and potential alternatives."
    />
    <meta
      name="keywords"
      content="Data,Dataviz,Datavisualization,Plot,Chart,Graph,R,Python,D3,Learning,Caveat,Pitfall,Mistake,Classification"
    />
    <meta name="author" content="Yan Holtz and Conor Healy" />
    <link rel="icon" href="img/logo/data-to-viz.ico" />

    <!-- Control appearance when share by social media -->
    <meta property="og:title" content="Network diagram" />
    <meta
      property="og:image"
      content="https://github.com/holtzy/data_to_viz/raw/master/img/section/NetworkSmall.png"
    />
    <meta
      property="og:description"
      content="An extensive description of Network
diagram. Definition, examples, input data, common caveats, tool to build it and potential alternatives."
    />
    <meta
      property="og:url"
      content="www.data-to-viz.com/caveat/network.html"
    />
    <meta property="og:type" content="website" />

    <style>
      .myheader {
        background-image: url("https://github.com/holtzy/data_to_viz/raw/master/img/overview_RGG_faded.png");
        min-height: 300px;
        background-size: 100% 100%;

        /* Create the parallax scrolling effect */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;

        height: 100%;
        width: 100% !important;
      }
      .mytitle {
        text-transform: uppercase;
        font-family: "Montserrat";
        font-size: 200%;
        font-weight: 500;
        letter-spacing: 4px;
      }
    </style>

    <div class="myheader" style="text-align: center">
      <br />
      <a href="http://www.data-to-viz.com"
        ><img
          align="left"
          src="https://github.com/holtzy/data_to_viz/raw/master/img/logo/typo.png"
          style="width: 150px; vertical-align: top; margin-left: 5%"
      /></a>
      <br /><br />
      <br /><br />
      <a href="http://www.data-to-viz.com">
        <img
          src="https://github.com/holtzy/data_to_viz/raw/master/img/section/NetworkSmall.png"
      /></a>
      <br /><br />
      <p class="mytitle">Network diagram</p>
      <p style="color: #d0d0d0">
        <a href="#definition">definition</a> - <a href="#mistake">mistake</a> -
        <a href="#related">related</a> -
        <a href="#code">code</a>
      </p>
    </div>

         <script src="libs/header-attrs-2.27/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/lumen.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
       h1.title {font-size: 38px;}
       h2 {font-size: 30px;}
       h3 {font-size: 24px;}
       h4 {font-size: 18px;}
       h5 {font-size: 16px;}
       h6 {font-size: 12px;}
       code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
       pre:not([class]) { background-color: white }</style>
<script src="libs/navigation-1.1/tabsets.js"></script>
<script src="libs/navigation-1.1/codefolding.js"></script>
<link href="libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
<script src="libs/pagedtable-1.1/js/pagedtable.js"></script>
<link href="libs/htmltools-fill-0.5.8.1/fill.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.6.4/htmlwidgets.js"></script>
<script src="libs/d3-4.5.0/d3.min.js"></script>
<script src="libs/forceNetwork-binding-0.4/forceNetwork.js"></script>       <style type="text/css">
      code {
        white-space: pre;
      }
    </style>
    <style type="text/css">
      pre > code.sourceCode { white-space: pre; position: relative; }
      pre > code.sourceCode > span { line-height: 1.25; }
      pre > code.sourceCode > span:empty { height: 1.2em; }
      .sourceCode { overflow: visible; }
      code.sourceCode > span { color: inherit; text-decoration: inherit; }
      div.sourceCode { margin: 1em 0; }
      pre.sourceCode { margin: 0; }
      @media screen {
      div.sourceCode { overflow: auto; }
      }
      @media print {
      pre > code.sourceCode { white-space: pre-wrap; }
      pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
      }
      pre.numberSource code
        { counter-reset: source-line 0; }
      pre.numberSource code > span
        { position: relative; left: -4em; counter-increment: source-line; }
      pre.numberSource code > span > a:first-child::before
        { content: counter(source-line);
          position: relative; left: -1em; text-align: right; vertical-align: baseline;
          border: none; display: inline-block;
          -webkit-touch-callout: none; -webkit-user-select: none;
          -khtml-user-select: none; -moz-user-select: none;
          -ms-user-select: none; user-select: none;
          padding: 0 4px; width: 4em;
          color: #aaaaaa;
        }
      pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
      div.sourceCode
        {   }
      @media screen {
      pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
      }
      code span.al { color: #ff0000; font-weight: bold; } /* Alert */
      code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
      code span.at { color: #7d9029; } /* Attribute */
      code span.bn { color: #40a070; } /* BaseN */
      code span.bu { color: #008000; } /* BuiltIn */
      code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
      code span.ch { color: #4070a0; } /* Char */
      code span.cn { color: #880000; } /* Constant */
      code span.co { color: #60a0b0; font-style: italic; } /* Comment */
      code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
      code span.do { color: #ba2121; font-style: italic; } /* Documentation */
      code span.dt { color: #902000; } /* DataType */
      code span.dv { color: #40a070; } /* DecVal */
      code span.er { color: #ff0000; font-weight: bold; } /* Error */
      code span.ex { } /* Extension */
      code span.fl { color: #40a070; } /* Float */
      code span.fu { color: #06287e; } /* Function */
      code span.im { color: #008000; font-weight: bold; } /* Import */
      code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
      code span.kw { color: #007020; font-weight: bold; } /* Keyword */
      code span.op { color: #666666; } /* Operator */
      code span.ot { color: #007020; } /* Other */
      code span.pp { color: #bc7a00; } /* Preprocessor */
      code span.sc { color: #4070a0; } /* SpecialChar */
      code span.ss { color: #bb6688; } /* SpecialString */
      code span.st { color: #4070a0; } /* String */
      code span.va { color: #19177c; } /* Variable */
      code span.vs { color: #4070a0; } /* VerbatimString */
      code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
            div.sourceCode {
        overflow-x: visible;
      }
          </style>
        <style type="text/css">
      pre:not([class]) {
        background-color: white;
      }
    </style>
           <style type="text/css">
      h1 {
        font-size: 34px;
      }
      h1.title {
        font-size: 38px;
      }
      h2 {
        font-size: 30px;
      }
      h3 {
        font-size: 24px;
      }
      h4 {
        font-size: 18px;
      }
      h5 {
        font-size: 16px;
      }
      h6 {
        font-size: 12px;
      }
      .table th:not([align]) {
        text-align: left;
      }
          </style>
         <link
      rel="stylesheet"
      href="style.css"
      type="text/css"
      
    />
      </head>

  <body>
        <style type="text/css">
      .main-container {
        max-width: 940px;
        margin-left: auto;
        margin-right: auto;
      }
      code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
      }
      img {
        max-width: 100%;
        height: auto;
      }
      .tabbed-pane {
        padding-top: 12px;
      }
      button.code-folding-btn:focus {
        outline: none;
      }
    </style>

     
    <div class="container-fluid main-container">
      <!-- tabsets -->
      <script>
        $(document).ready(function () {
          window.buildTabsets("TOC");
        });
      </script>

      <!-- code folding -->
            <style type="text/css">
        .code-folding-btn {
          margin-bottom: 4px;
        }
      </style>
      <script>
        $(document).ready(function () {
                          window.initializeCodeFolding("hide" === "show");
                });
      </script>
         
                    <div class="fluid-row" id="header">
                        <div class="btn-group pull-right">
              <button
                type="button"
                class="btn btn-default btn-xs dropdown-toggle"
                data-toggle="dropdown"
                aria-haspopup="true"
                aria-expanded="false"
              >
                <span>Show Code</span> <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" style="min-width: 50px">
                                <li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
                <li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
                                </ul>
            </div>

                         </div>

              <div class="mycontent">
<div id="definition" class="section level1">
<h1>Definition</h1>
<hr />
<p><code>Network diagrams</code> (also called Graphs) show
interconnections between a set of entities. Each entity is represented
by a <code>Node</code> (or vertice). Connections between nodes are
represented through <code>links</code> (or edges).</p>
<p>Here is an example showing the co-authors network of <a
href="https://sites.google.com/site/ranwez/">Vincent Ranwez</a>, a
researcher who’s my previous supervisor. Basically, people having
published at least one research paper with him are represented by a
node. If two people have been listed on the same publication at least
once, they are connected by a link.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="co"># Libraries</span></span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="fu">library</span>(viridis)</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="fu">library</span>(patchwork)</span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a><span class="fu">library</span>(hrbrthemes)</span>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a><span class="fu">library</span>(ggraph)</span>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a><span class="fu">library</span>(igraph)</span>
<span id="cb1-8"><a href="#cb1-8" tabindex="-1"></a><span class="fu">library</span>(networkD3)</span>
<span id="cb1-9"><a href="#cb1-9" tabindex="-1"></a></span>
<span id="cb1-10"><a href="#cb1-10" tabindex="-1"></a><span class="co"># Load researcher data</span></span>
<span id="cb1-11"><a href="#cb1-11" tabindex="-1"></a>dataUU <span class="ot">&lt;-</span> <span class="fu">read.table</span>(<span class="st">&quot;https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/13_AdjacencyUndirectedUnweighted.csv&quot;</span>, <span class="at">header=</span><span class="cn">TRUE</span>)</span>
<span id="cb1-12"><a href="#cb1-12" tabindex="-1"></a></span>
<span id="cb1-13"><a href="#cb1-13" tabindex="-1"></a><span class="co"># Transform the adjacency matrix in a long format</span></span>
<span id="cb1-14"><a href="#cb1-14" tabindex="-1"></a>connect <span class="ot">&lt;-</span> dataUU <span class="sc">%&gt;%</span></span>
<span id="cb1-15"><a href="#cb1-15" tabindex="-1"></a>  <span class="fu">gather</span>(<span class="at">key=</span><span class="st">&quot;to&quot;</span>, <span class="at">value=</span><span class="st">&quot;value&quot;</span>, <span class="sc">-</span><span class="dv">1</span>) <span class="sc">%&gt;%</span></span>
<span id="cb1-16"><a href="#cb1-16" tabindex="-1"></a>  <span class="fu">na.omit</span>()</span>
<span id="cb1-17"><a href="#cb1-17" tabindex="-1"></a></span>
<span id="cb1-18"><a href="#cb1-18" tabindex="-1"></a><span class="co"># Number of connection per person</span></span>
<span id="cb1-19"><a href="#cb1-19" tabindex="-1"></a><span class="fu">c</span>(<span class="fu">as.character</span>(connect<span class="sc">$</span>from), <span class="fu">as.character</span>(connect<span class="sc">$</span>to)) <span class="sc">%&gt;%</span></span>
<span id="cb1-20"><a href="#cb1-20" tabindex="-1"></a>  <span class="fu">as_tibble</span>() <span class="sc">%&gt;%</span></span>
<span id="cb1-21"><a href="#cb1-21" tabindex="-1"></a>  <span class="fu">group_by</span>(value) <span class="sc">%&gt;%</span></span>
<span id="cb1-22"><a href="#cb1-22" tabindex="-1"></a>  <span class="fu">summarize</span>(<span class="at">n=</span><span class="fu">n</span>()) <span class="ot">-&gt;</span> coauth</span>
<span id="cb1-23"><a href="#cb1-23" tabindex="-1"></a><span class="fu">colnames</span>(coauth) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">&quot;name&quot;</span>, <span class="st">&quot;n&quot;</span>)</span>
<span id="cb1-24"><a href="#cb1-24" tabindex="-1"></a></span>
<span id="cb1-25"><a href="#cb1-25" tabindex="-1"></a><span class="co"># NetworkD3 format</span></span>
<span id="cb1-26"><a href="#cb1-26" tabindex="-1"></a>graph <span class="ot">&lt;-</span> <span class="fu">simpleNetwork</span>(connect)</span>
<span id="cb1-27"><a href="#cb1-27" tabindex="-1"></a></span>
<span id="cb1-28"><a href="#cb1-28" tabindex="-1"></a><span class="co"># Plot</span></span>
<span id="cb1-29"><a href="#cb1-29" tabindex="-1"></a><span class="fu">simpleNetwork</span>(connect,</span>
<span id="cb1-30"><a href="#cb1-30" tabindex="-1"></a>        <span class="at">Source =</span> <span class="dv">1</span>,                 <span class="co"># column number of source</span></span>
<span id="cb1-31"><a href="#cb1-31" tabindex="-1"></a>        <span class="at">Target =</span> <span class="dv">2</span>,                 <span class="co"># column number of target</span></span>
<span id="cb1-32"><a href="#cb1-32" tabindex="-1"></a>        <span class="at">height =</span> <span class="dv">880</span>,               <span class="co"># height of frame area in pixels</span></span>
<span id="cb1-33"><a href="#cb1-33" tabindex="-1"></a>        <span class="at">width =</span> <span class="dv">1980</span>,</span>
<span id="cb1-34"><a href="#cb1-34" tabindex="-1"></a>        <span class="at">linkDistance =</span> <span class="dv">10</span>,         <span class="co"># distance between node. Increase this value to have more space between nodes</span></span>
<span id="cb1-35"><a href="#cb1-35" tabindex="-1"></a>        <span class="at">charge =</span> <span class="sc">-</span><span class="dv">4</span>,              <span class="co"># numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value)</span></span>
<span id="cb1-36"><a href="#cb1-36" tabindex="-1"></a>        <span class="at">fontSize =</span> <span class="dv">5</span>,              <span class="co"># size of the node names</span></span>
<span id="cb1-37"><a href="#cb1-37" tabindex="-1"></a>        <span class="at">fontFamily =</span> <span class="st">&quot;serif&quot;</span>,       <span class="co"># font og node names</span></span>
<span id="cb1-38"><a href="#cb1-38" tabindex="-1"></a>        <span class="at">linkColour =</span> <span class="st">&quot;#666&quot;</span>,        <span class="co"># colour of edges, MUST be a common colour for the whole graph</span></span>
<span id="cb1-39"><a href="#cb1-39" tabindex="-1"></a>        <span class="at">nodeColour =</span> <span class="st">&quot;#69b3a2&quot;</span>,     <span class="co"># colour of nodes, MUST be a common colour for the whole graph</span></span>
<span id="cb1-40"><a href="#cb1-40" tabindex="-1"></a>        <span class="at">opacity =</span> <span class="fl">0.9</span>,              <span class="co"># opacity of nodes. 0=transparent. 1=no transparency</span></span>
<span id="cb1-41"><a href="#cb1-41" tabindex="-1"></a>        <span class="at">zoom =</span> T                    <span class="co"># Can you zoom on the figure?</span></span>
<span id="cb1-42"><a href="#cb1-42" tabindex="-1"></a>        )</span></code></pre></div>
<div class="forceNetwork html-widget html-fill-item" id="htmlwidget-291ce26e8a3651b9ac5c" style="width:864px;height:672px;"></div>
<script type="application/json" data-for="htmlwidget-291ce26e8a3651b9ac5c">{"x":{"links":{"source":[174,130,221,0,80,175,38,114,207,63,121,53,142,159,0,3,74,80,175,97,144,112,183,201,64,70,98,116,154,36,127,225,7,63,121,60,91,7,26,63,121,33,38,93,179,196,225,4,38,114,6,65,70,106,112,114,172,179,181,201,202,207,220,117,134,51,162,203,27,60,91,1,174,199,205,222,8,53,142,159,11,131,182,159,91,95,177,75,148,172,207,98,202,6,38,64,75,98,116,120,148,154,182,207,211,35,196,133,144,0,3,80,175,27,38,49,60,70,91,98,120,152,154,182,8,50,53,142,159,108,126,154,180,210,0,0,3,9,74,80,175,2,83,94,130,132,160,164,185,212,221,94,130,136,185,221,163,208,38,112,124,25,36,127,225,38,92,179,83,130,136,185,84,163,208,24,144,153,182,38,70,116,154,92,93,180,126,154,180,210,221,21,38,183,201,45,117,134,150,197,23,64,70,98,154,134,38,62,70,75,95,98,154,177,180,63,38,112,154,36,225,34,38,83,93,94,132,136,179,185,212,221,84,96,163,208,221,10,97,99,144,110,53,159,24,110,135,165,75,120,45,117,134,197,75,152,184,11,52,92,93,106,180,38,62,64,70,75,95,98,116,120,177,180,130,132,212,221,24,97,144,51,208,2,130,221,2,82,110,130,132,135,160,164,212,221,47,51,162,203,6,207,0,80,75,151,152,184,95,110,135,146,165,185,62,83,92,93,95,126,130,154,177,185,221,6,172,207,131,153,112,201,75,152,4,37,38,83,94,110,114,130,135,136,146,165,221,45,117,134,1,174,205,51,162,1,174,5,21,38,75,89,106,112,124,151,152,176,183,184,201,209,218,38,106,112,207,126,154,180,38,207,2,34,38,82,93,130,132,164,165,179,221,38,94,110,135,146,165,178,185,1,174,199,205],"target":[12,13,13,14,14,14,15,15,16,17,17,18,18,18,19,19,19,19,19,20,20,22,22,22,28,28,28,28,28,29,29,29,30,30,30,31,31,32,32,32,32,39,40,40,40,41,42,43,43,43,44,44,44,44,44,44,44,44,44,44,44,44,44,46,46,48,48,48,54,54,54,55,55,55,55,55,56,56,56,56,57,58,58,59,61,66,66,67,67,67,67,68,69,71,71,71,71,71,71,71,71,71,71,71,71,72,72,73,73,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,79,79,79,79,79,81,85,85,85,85,85,85,86,86,86,86,86,86,86,86,86,86,87,87,87,87,87,88,88,90,90,90,100,100,100,100,101,101,101,102,102,102,102,103,103,103,104,104,104,104,105,105,105,105,107,107,107,109,109,109,109,111,113,113,113,113,115,115,115,115,115,118,118,118,118,118,119,122,122,122,122,122,122,122,122,122,123,125,125,128,129,129,137,137,137,137,137,137,137,137,137,137,137,138,138,138,138,139,140,140,140,140,141,143,143,145,147,147,147,149,149,155,155,155,155,156,156,156,157,157,157,157,157,157,158,158,158,158,158,158,158,158,158,158,158,161,161,161,161,166,166,166,167,168,169,169,169,170,170,170,170,170,170,170,170,170,170,171,171,171,171,173,173,186,186,187,187,187,187,188,189,189,189,189,189,190,190,190,190,190,190,190,190,190,190,190,191,191,191,192,192,193,193,194,194,195,195,195,195,195,195,195,195,195,195,195,195,195,198,198,198,200,200,200,204,204,206,206,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,214,214,214,214,215,215,215,216,216,217,217,217,217,217,217,217,217,217,217,217,219,223,223,223,223,223,223,223,224,224,224,224],"value":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"colour":["#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666","#666"]},"nodes":{"name":["A Armero","A Bateman","A Besnard","A Breil","A Cenci","A Chifolleau","A Criscuolo","A Dassouli","A Dellagi","A Dereeper","A Regnault","A Serra","A.Bateman","A.Besnard","A.Breil","A.Cenci","A.Criscuolo","A.Dassouli","A.Dellagi","A.Dereeper","A.Regnault","AMA Chifolleau","AMA.Chifolleau","B Boussau","B Duthil","B Martret","B Noel","B Roure","B.Boussau","B.Martret","B.Noel","B.Roure","B.Vacherie","C Abessolo","C Burgarella","C Douady","C Fizames","C Guilhaumon","C Scornavacca","C.Abessolo","C.Burgarella","C.Douady","C.Fizames","C.Guilhaumon","C.Scornavacca","CP Meyer","CP.Meyer","CW Kilpatrick","CW.Kilpatrick","D Baurain","D Expert","D Huchon","D Pot","D Vile","D.Baurain","D.Durand","D.Expert","D.Pot","D.Sánchez","D.Vile","DMD Vienne","DMD.Vienne","E Bazin","E Cornillot","E Figuet","E Jacox","E.Bazin","E.Douzery","E.Figuet","E.Jacox","EJP Douzery","EJP.Douzery","EJPDNLH.Philippe","EMA.LGI2P","F De Lamotte","F Delsuc","F.De.Lamotte","F.Delsuc","F.Gosti","F.Zhang","FC Baurens","FC.Baurens","G Poux","G Sarah","G Tsagkogeorga","G.Droc","G.Poux","G.Sarah","G.Tsagkogeorga","GJ Szöllősi","GJ.Szöllősi","H Philippe","I Fischer","J Dainat","J David","J Dutheil","J Melo‐Ferreira","J Montmain","J Romiguier","J Villerd","J.Alassimone","J.Dainat","J.David","J.Melo.Ferreira","J.Montmain","J.Romiguier","JF Dufayard","JF.Dufayard","JH Wilson","JH.Wilson","JL David","JL.David","JP Doyon","JP.Doyon","JS Escobar","JT.Boehm","JY Dutheil","JY Yang","JY.Dutheil","JY.Yang","K Belkhir","K Hadj-Kaddour","K.Belkhir","K.Hadj.Kaddour","KY Gorbunov","KY.Gorbunov","L Duret","L Marquès","L.Duret","L.Marquès","M Ardisson","M Batet","M Bonnefoy","M Crampes","M Leray","M Tavaud","M Tavaud-Pirra","M.Ardisson","M.Ballenghien","M.Bonnefoy","M.Crampes","M.Tavaud","MC SOULIE","MC.SOULIE","MF Sy","MF.Sy","MH Muller","MH.Muller","MK Tilak","MK.Tilak","N Agudelo","N Auberval","N Clairon","N Fiorini","N Galtier","N.Agudelo","N.Auberval","N.Chantret","N.Galtier","NNT Nguyen","NO Rode","NO.Rode","P Chevret","P Gayral","P Leroy","P Roumet","P.Augereau","P.Chevret","P.Gayral","P.Leroy","P.Roumet","PD.Jenkins","PH Fabre","PH.Fabre","RF Murphy","S Bocs","S Diser","S Gaillard","S Gautier","S Glemin","S Glémin","S Guillemot","S Harispe","S Pointet","S Pourali","S Santoni","S.Bocs","S.Diser","S.Gaillard","S.Gautier","S.Glémin","S.Guillemot","S.Harispe","S.Pointet","S.Pourali","S.Santoni","SBACF Delsuc","SC Mills","SC.Mills","T Lengauer","T.Lengauer","TH Nguyen","TH To","U Jordan","U.Jordan","UK Hinxton","UK.Hinxton","V Berry","V Cahais","V Daubin","V Dion","V Lefort","V Viader","V.Berry","V.Daubin","V.Dion","V.Lefort","V.Viader","W Paprotny","W.Paprotny","Y Chan","Y Holtz","Y Moreau","Y.Holtz","Y.Moreau","Z Shahzad"],"group":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"nodesize":[8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8]},"options":{"NodeID":"name","Group":"group","colourScale":"d3.scaleOrdinal(['#69b3a2'])","fontSize":5,"fontFamily":"serif","clickTextSize":12.5,"linkDistance":10,"linkWidth":"'1.5px'.toString()","charge":-4,"opacity":0.9,"zoom":true,"legend":false,"arrows":false,"nodesize":true,"radiusCalculation":"d.nodesize","bounded":false,"opacityNoHover":1,"clickAction":null}},"evals":[],"jsHooks":[]}</script>
<p><em>Note</em>: This chart is <code>interactive</code>: zoom on a
specific cluster to see researcher names. Data have been retrieved using
the <a href="https://github.com/jkeirstead/scholar">scholar</a> package,
the pipeline is describe in this <a
href="https://github.com/holtzy/Google-Scholar-Network">github
repository</a>. You can read more about this story <a
href="https://www.data-to-viz.com/story/AdjacencyMatrix.html">here</a>.</p>
</div>
<div id="four-types-of-input" class="section level1">
<h1>Four types of input</h1>
<hr />
<p>Four main types of network diagram exist, according to the features
of data inputs. Here is a short description. <br></p>
</div>
</div>
<div class="row"
style="padding-left: 50px; padding-right: 50px; margin-left: auto; margin-right: auto;">
<div class="col-md-3 col-sm-6">
<p><br></p>
<h4>
<code>Undirected and Unweighted</code>
</h4>
<p>Tom, Cherelle and Melanie live in the same house. They are connected
but no direction and no weight.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="co"># Create data</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2</span>)</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a>data <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="fu">sample</span>(<span class="dv">0</span><span class="sc">:</span><span class="dv">1</span>, <span class="dv">25</span>, <span class="at">replace=</span><span class="cn">TRUE</span>), <span class="at">nrow=</span><span class="dv">5</span>)</span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a>data[<span class="fu">lower.tri</span>(data)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a><span class="fu">rownames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb2-6"><a href="#cb2-6" tabindex="-1"></a><span class="fu">colnames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb2-7"><a href="#cb2-7" tabindex="-1"></a></span>
<span id="cb2-8"><a href="#cb2-8" tabindex="-1"></a><span class="co"># Transform it in a graph format</span></span>
<span id="cb2-9"><a href="#cb2-9" tabindex="-1"></a>network <span class="ot">&lt;-</span> <span class="fu">graph_from_adjacency_matrix</span>(data)</span>
<span id="cb2-10"><a href="#cb2-10" tabindex="-1"></a></span>
<span id="cb2-11"><a href="#cb2-11" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb2-12"><a href="#cb2-12" tabindex="-1"></a><span class="fu">ggraph</span>(network) <span class="sc">+</span></span>
<span id="cb2-13"><a href="#cb2-13" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.3</span>, <span class="at">edge_width=</span><span class="fl">0.2</span>) <span class="sc">+</span></span>
<span id="cb2-14"><a href="#cb2-14" tabindex="-1"></a>  <span class="fu">geom_node_point</span>( <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>, <span class="at">size=</span><span class="dv">5</span>) <span class="sc">+</span></span>
<span id="cb2-15"><a href="#cb2-15" tabindex="-1"></a>  <span class="fu">geom_node_text</span>( <span class="fu">aes</span>(<span class="at">label=</span>name), <span class="at">repel =</span> <span class="cn">TRUE</span>, <span class="at">size=</span><span class="dv">8</span>, <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>) <span class="sc">+</span></span>
<span id="cb2-16"><a href="#cb2-16" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb2-17"><a href="#cb2-17" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb2-18"><a href="#cb2-18" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb2-19"><a href="#cb2-19" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb2-20"><a href="#cb2-20" tabindex="-1"></a>  )</span></code></pre></div>
<p><img src="network_files/figure-html/unnamed-chunk-2-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div class="col-md-3 col-sm-6">
<br>
<h4>
<code>Undirected and Weighted</code>
</h4>
<p>In the previous co-authors network, people are connected if they
published a scientific paper together. The weight is the number of time
it happend.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="co"># Create data</span></span>
<span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">1</span>)</span>
<span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a>data <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="fu">sample</span>(<span class="dv">0</span><span class="sc">:</span><span class="dv">3</span>, <span class="dv">25</span>, <span class="at">replace=</span><span class="cn">TRUE</span>), <span class="at">nrow=</span><span class="dv">5</span>)</span>
<span id="cb3-4"><a href="#cb3-4" tabindex="-1"></a>data[<span class="fu">lower.tri</span>(data)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a><span class="fu">rownames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a><span class="fu">colnames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a></span>
<span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a><span class="co"># Transform it in a graph format</span></span>
<span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a>network <span class="ot">&lt;-</span> <span class="fu">graph_from_adjacency_matrix</span>(data, <span class="at">weighted =</span> <span class="cn">TRUE</span>)</span>
<span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a></span>
<span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a><span class="co"># Remove edges with NA weights</span></span>
<span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a>network <span class="ot">&lt;-</span> <span class="fu">delete_edges</span>(network, <span class="fu">E</span>(network)[<span class="fu">is.na</span>(<span class="fu">E</span>(network)<span class="sc">$</span>weight)])</span>
<span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a></span>
<span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a><span class="fu">ggraph</span>(network) <span class="sc">+</span></span>
<span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="fu">aes</span>(<span class="at">edge_width=</span><span class="fu">E</span>(network)<span class="sc">$</span>weight), <span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.3</span>) <span class="sc">+</span></span>
<span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a>  <span class="fu">geom_node_point</span>(<span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>, <span class="at">size=</span><span class="dv">5</span>) <span class="sc">+</span></span>
<span id="cb3-18"><a href="#cb3-18" tabindex="-1"></a>  <span class="fu">geom_node_text</span>(<span class="fu">aes</span>(<span class="at">label=</span>name), <span class="at">repel =</span> <span class="cn">TRUE</span>, <span class="at">size=</span><span class="dv">8</span>, <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>) <span class="sc">+</span></span>
<span id="cb3-19"><a href="#cb3-19" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb3-20"><a href="#cb3-20" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb3-21"><a href="#cb3-21" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb3-22"><a href="#cb3-22" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb3-23"><a href="#cb3-23" tabindex="-1"></a>  )</span></code></pre></div>
<p><img src="network_files/figure-html/unnamed-chunk-3-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div class="col-md-3 col-sm-6">
<br>
<h4>
<code>Directed and Unweighted</code>
</h4>
<p>Tom follows Shirley on twitter, but the opposite is not necessarily
true. The connection is unweighted: just connected or not.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="co"># Create data</span></span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">10</span>)</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a>data <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="fu">sample</span>(<span class="dv">0</span><span class="sc">:</span><span class="dv">1</span>, <span class="dv">25</span>, <span class="at">replace=</span><span class="cn">TRUE</span>), <span class="at">nrow=</span><span class="dv">5</span>)</span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a><span class="fu">diag</span>(data) <span class="ot">=</span> <span class="cn">NA</span></span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a><span class="fu">rownames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a><span class="fu">colnames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]</span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a></span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a><span class="co"># Transform it in a graph format</span></span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a>network <span class="ot">&lt;-</span> <span class="fu">graph_from_adjacency_matrix</span>(data)</span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a></span>
<span id="cb4-11"><a href="#cb4-11" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a><span class="fu">ggraph</span>(network) <span class="sc">+</span></span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.8</span>, <span class="at">edge_width=</span><span class="fl">0.2</span>, <span class="at">arrow =</span> <span class="fu">arrow</span>(<span class="at">angle=</span><span class="dv">20</span>)) <span class="sc">+</span></span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a>  <span class="fu">geom_node_point</span>( <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>, <span class="at">size=</span><span class="dv">3</span>) <span class="sc">+</span></span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a>  <span class="fu">geom_node_text</span>( <span class="fu">aes</span>(<span class="at">label=</span>name), <span class="at">repel =</span> <span class="cn">TRUE</span>, <span class="at">size=</span><span class="dv">6</span>, <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>) <span class="sc">+</span></span>
<span id="cb4-16"><a href="#cb4-16" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb4-17"><a href="#cb4-17" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb4-18"><a href="#cb4-18" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb4-19"><a href="#cb4-19" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb4-20"><a href="#cb4-20" tabindex="-1"></a>  )</span></code></pre></div>
<p><img src="network_files/figure-html/unnamed-chunk-4-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div class="col-md-3 col-sm-6">
<p><br></p>
<h4>
<code>Directed and Weighted</code>
</h4>
<p>People migrate from a country to another: the weight is the number of
people, the direction is the destination.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="co"># Create data</span></span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">11</span>)</span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a>data <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="fu">sample</span>(<span class="dv">0</span><span class="sc">:</span><span class="dv">3</span>, <span class="dv">16</span>, <span class="at">replace=</span><span class="cn">TRUE</span>), <span class="at">nrow=</span><span class="dv">4</span>)</span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a><span class="fu">diag</span>(data) <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb5-5"><a href="#cb5-5" tabindex="-1"></a><span class="fu">rownames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>]</span>
<span id="cb5-6"><a href="#cb5-6" tabindex="-1"></a><span class="fu">colnames</span>(data) <span class="ot">&lt;-</span> LETTERS[<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>]</span>
<span id="cb5-7"><a href="#cb5-7" tabindex="-1"></a></span>
<span id="cb5-8"><a href="#cb5-8" tabindex="-1"></a><span class="co"># Transform it in a graph format</span></span>
<span id="cb5-9"><a href="#cb5-9" tabindex="-1"></a>network<span class="ot">=</span><span class="fu">graph_from_adjacency_matrix</span>(data, <span class="at">weighted=</span><span class="cn">TRUE</span>)</span>
<span id="cb5-10"><a href="#cb5-10" tabindex="-1"></a></span>
<span id="cb5-11"><a href="#cb5-11" tabindex="-1"></a><span class="co"># Remove edges with NA weights</span></span>
<span id="cb5-12"><a href="#cb5-12" tabindex="-1"></a>network <span class="ot">&lt;-</span> <span class="fu">delete_edges</span>(network, <span class="fu">E</span>(network)[<span class="fu">is.na</span>(<span class="fu">E</span>(network)<span class="sc">$</span>weight)])</span>
<span id="cb5-13"><a href="#cb5-13" tabindex="-1"></a></span>
<span id="cb5-14"><a href="#cb5-14" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb5-15"><a href="#cb5-15" tabindex="-1"></a><span class="fu">ggraph</span>(network) <span class="sc">+</span></span>
<span id="cb5-16"><a href="#cb5-16" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.3</span>, <span class="fu">aes</span>(<span class="at">edge_width=</span><span class="fu">E</span>(network)<span class="sc">$</span>weight) , <span class="at">arrow=</span><span class="fu">arrow</span>()) <span class="sc">+</span></span>
<span id="cb5-17"><a href="#cb5-17" tabindex="-1"></a>  <span class="fu">scale_edge_width</span>(<span class="at">range=</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">3</span>)) <span class="sc">+</span></span>
<span id="cb5-18"><a href="#cb5-18" tabindex="-1"></a>  <span class="fu">geom_node_point</span>( <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>, <span class="at">size=</span><span class="dv">3</span>) <span class="sc">+</span></span>
<span id="cb5-19"><a href="#cb5-19" tabindex="-1"></a>  <span class="fu">geom_node_text</span>( <span class="fu">aes</span>(<span class="at">label=</span>name), <span class="at">repel =</span> <span class="cn">TRUE</span>, <span class="at">size=</span><span class="dv">6</span>, <span class="at">color=</span><span class="st">&quot;#69b3a2&quot;</span>) <span class="sc">+</span></span>
<span id="cb5-20"><a href="#cb5-20" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb5-21"><a href="#cb5-21" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb5-22"><a href="#cb5-22" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb5-23"><a href="#cb5-23" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb5-24"><a href="#cb5-24" tabindex="-1"></a>  )</span></code></pre></div>
<p><img src="network_files/figure-html/unnamed-chunk-5-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
</div>
<div class="mycontent">
<p><br><br></p>
<p><em>Note</em>: as you can observe on the examples above, directed
graphs are quite hard to represent using this type of visualization.
More appropriate techniques exist to represent flows, like <a
href="https://www.data-to-viz.com/graph/sankey.html">Sankey diagram</a>
or <a href="https://www.data-to-viz.com/graph/chord.html">chord
diagram</a>.</p>
<div id="variation" class="section level1">
<h1>Variation</h1>
<hr />
<p>Many customizations are available for network diagrams. Here are a
few features you can work on to improve your graphic:</p>
<ul>
<li><p>Adding information to the node: you can add more insight to the
graphic by customizing the color, the shape or the size of each node
according to other variables.</p></li>
<li><p>Different <code>layout algorythm</code>: finding the most optimal
position for each node is a tricky exercise that highly impacts the
output. Several algorithms have been developped, and choosing the right
one for your data is a crucial step. See <a
href="http://igraph.org/r/doc/layout_.html">this page</a> for a list of
the most common algorithm. Here is an example illustrating the
differences between three options: <br><br></p></li>
</ul>
</div>
</div>
<div class = "col-md-4 col-sm-12">
<br>
<h4>
<code>Fruchterman-Reingold</code>
</h4>
<hr>
<p>Probably the most widely used algorithm, using a force-directed
method.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="co"># Load researcher data</span></span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a>dataUU <span class="ot">&lt;-</span> <span class="fu">read.table</span>(<span class="st">&quot;https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/13_AdjacencyUndirectedUnweighted.csv&quot;</span>, <span class="at">header=</span><span class="cn">TRUE</span>)</span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a><span class="co"># Transform the adjacency matrix in a long format</span></span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a>connect <span class="ot">&lt;-</span> dataUU <span class="sc">%&gt;%</span></span>
<span id="cb6-6"><a href="#cb6-6" tabindex="-1"></a>  <span class="fu">gather</span>(<span class="at">key=</span><span class="st">&quot;to&quot;</span>, <span class="at">value=</span><span class="st">&quot;value&quot;</span>, <span class="sc">-</span><span class="dv">1</span>) <span class="sc">%&gt;%</span></span>
<span id="cb6-7"><a href="#cb6-7" tabindex="-1"></a>  <span class="fu">na.omit</span>()</span>
<span id="cb6-8"><a href="#cb6-8" tabindex="-1"></a></span>
<span id="cb6-9"><a href="#cb6-9" tabindex="-1"></a><span class="co"># Number of connection per person</span></span>
<span id="cb6-10"><a href="#cb6-10" tabindex="-1"></a><span class="fu">c</span>( <span class="fu">as.character</span>(connect<span class="sc">$</span>from), <span class="fu">as.character</span>(connect<span class="sc">$</span>to)) <span class="sc">%&gt;%</span></span>
<span id="cb6-11"><a href="#cb6-11" tabindex="-1"></a>  <span class="fu">as.tibble</span>() <span class="sc">%&gt;%</span></span>
<span id="cb6-12"><a href="#cb6-12" tabindex="-1"></a>  <span class="fu">group_by</span>(value) <span class="sc">%&gt;%</span></span>
<span id="cb6-13"><a href="#cb6-13" tabindex="-1"></a>  <span class="fu">summarize</span>(<span class="at">n=</span><span class="fu">n</span>()) <span class="ot">-&gt;</span> coauth</span>
<span id="cb6-14"><a href="#cb6-14" tabindex="-1"></a><span class="fu">colnames</span>(coauth) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">&quot;name&quot;</span>, <span class="st">&quot;n&quot;</span>)</span>
<span id="cb6-15"><a href="#cb6-15" tabindex="-1"></a></span>
<span id="cb6-16"><a href="#cb6-16" tabindex="-1"></a><span class="co"># Create a graph object with igraph</span></span>
<span id="cb6-17"><a href="#cb6-17" tabindex="-1"></a>mygraph <span class="ot">&lt;-</span> <span class="fu">graph_from_data_frame</span>( connect, <span class="at">vertices =</span> coauth )</span>
<span id="cb6-18"><a href="#cb6-18" tabindex="-1"></a></span>
<span id="cb6-19"><a href="#cb6-19" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb6-20"><a href="#cb6-20" tabindex="-1"></a><span class="fu">ggraph</span>(mygraph, <span class="at">layout=</span><span class="st">&quot;fr&quot;</span>) <span class="sc">+</span></span>
<span id="cb6-21"><a href="#cb6-21" tabindex="-1"></a>  <span class="co">#geom_edge_density(edge_fill=&quot;#69b3a2&quot;) +</span></span>
<span id="cb6-22"><a href="#cb6-22" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.2</span>, <span class="at">edge_width=</span><span class="fl">0.3</span>) <span class="sc">+</span></span>
<span id="cb6-23"><a href="#cb6-23" tabindex="-1"></a>  <span class="fu">geom_node_point</span>(<span class="fu">aes</span>(<span class="at">size=</span>n, <span class="at">alpha=</span>n)) <span class="sc">+</span></span>
<span id="cb6-24"><a href="#cb6-24" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb6-25"><a href="#cb6-25" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb6-26"><a href="#cb6-26" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb6-27"><a href="#cb6-27" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb6-28"><a href="#cb6-28" tabindex="-1"></a>  )</span></code></pre></div>
<img src="network_files/figure-html/unnamed-chunk-6-1.png" width="672" style="display: block; margin: auto;" />
</div>
<div class = "col-md-4 col-sm-12">
<br>
<h4>
<code>DrL</code>
</h4>
<hr>
<p>A force-directed graph layout toolbox focused on real-world
large-scale graphs</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a><span class="co"># Make the graph</span></span>
<span id="cb7-2"><a href="#cb7-2" tabindex="-1"></a><span class="fu">ggraph</span>(mygraph, <span class="at">layout=</span><span class="st">&quot;drl&quot;</span>) <span class="sc">+</span></span>
<span id="cb7-3"><a href="#cb7-3" tabindex="-1"></a>  <span class="co">#geom_edge_density(edge_fill=&quot;#69b3a2&quot;) +</span></span>
<span id="cb7-4"><a href="#cb7-4" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.2</span>, <span class="at">edge_width=</span><span class="fl">0.3</span>) <span class="sc">+</span></span>
<span id="cb7-5"><a href="#cb7-5" tabindex="-1"></a>  <span class="fu">geom_node_point</span>(<span class="fu">aes</span>(<span class="at">size=</span>n, <span class="at">alpha=</span>n)) <span class="sc">+</span></span>
<span id="cb7-6"><a href="#cb7-6" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb7-7"><a href="#cb7-7" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb7-8"><a href="#cb7-8" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb7-9"><a href="#cb7-9" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb7-10"><a href="#cb7-10" tabindex="-1"></a>  )</span></code></pre></div>
<img src="network_files/figure-html/unnamed-chunk-7-1.png" width="672" style="display: block; margin: auto;" />
</div>
<div class = "col-md-4 col-sm-12">
<br>
<h4>
<code>Randomly</code>
</h4>
<hr>
<p>This is what happens if node positions is set up randomly</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a><span class="fu">ggraph</span>(mygraph, <span class="at">layout=</span><span class="st">&quot;igraph&quot;</span>, <span class="at">algorithm=</span><span class="st">&quot;randomly&quot;</span>) <span class="sc">+</span></span>
<span id="cb8-2"><a href="#cb8-2" tabindex="-1"></a>  <span class="co">#geom_edge_density(edge_fill=&quot;#69b3a2&quot;) +</span></span>
<span id="cb8-3"><a href="#cb8-3" tabindex="-1"></a>  <span class="fu">geom_edge_link</span>(<span class="at">edge_colour=</span><span class="st">&quot;black&quot;</span>, <span class="at">edge_alpha=</span><span class="fl">0.2</span>, <span class="at">edge_width=</span><span class="fl">0.3</span>) <span class="sc">+</span></span>
<span id="cb8-4"><a href="#cb8-4" tabindex="-1"></a>  <span class="fu">geom_node_point</span>(<span class="fu">aes</span>(<span class="at">size=</span>n, <span class="at">alpha=</span>n)) <span class="sc">+</span></span>
<span id="cb8-5"><a href="#cb8-5" tabindex="-1"></a>  <span class="fu">theme_void</span>() <span class="sc">+</span></span>
<span id="cb8-6"><a href="#cb8-6" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb8-7"><a href="#cb8-7" tabindex="-1"></a>    <span class="at">legend.position=</span><span class="st">&quot;none&quot;</span>,</span>
<span id="cb8-8"><a href="#cb8-8" tabindex="-1"></a>    <span class="at">plot.margin=</span><span class="fu">unit</span>(<span class="fu">rep</span>(<span class="dv">1</span>,<span class="dv">4</span>), <span class="st">&quot;cm&quot;</span>)</span>
<span id="cb8-9"><a href="#cb8-9" tabindex="-1"></a>  )</span></code></pre></div>
<p><img src="network_files/figure-html/unnamed-chunk-8-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
</div>
<div class="mycontent">
<div id="mistake" class="section level1">
<h1>Common mistakes</h1>
<hr />
<p><code>Hairball</code> is the main caveat when ploting networks: when
too many connections and no obivious pattern is represented, the figure
get cluttered and unreadable.</p>
</div>
<div id="related" class="section level1">
<h1>Related</h1>
<hr />
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="https://www.data-to-viz.com/graph/chord.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/ChordSmall.png">
<p class="mytitlerelated">
Chord diagram
</p>
<p class="mytextrelated">
A circular layout used to display weighted relationships between
entities through arcs.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="https://www.data-to-viz.com/graph/arc.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/ArcSmal.png">
<p class="mytitlerelated">
Arc diagram
</p>
<p class="mytextrelated">
A subset of the network diagram where nodes are aligned and edges are
arcs.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="https://www.data-to-viz.com/graph/sankey.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/SankeySmall.png">
<p class="mytitlerelated">
Sankey diagram
</p>
<p class="mytextrelated">
A flow diagram in which the width of the arrows is shown proportionally
to the flow quantity.
</p>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-6">
<a href="https://www.data-to-viz.com/graph/edge_bundling.html" class="btn btn-primary mybtnrelated" style="margin-bottom:4px;white-space: normal !important;">
<img  src="https://github.com/holtzy/data_to_viz/raw/master/img/section/BundleSmall.png">
<p class="mytitlerelated">
Edge bundling
</p>
<p class="mytextrelated">
Show connections between entities organized in a hierarchy.
</p>
</a>
</div>
</div>
</div>
<div id="code" class="section level1">
<h1>Build your own</h1>
<hr />
<p>The <a href="https://www.r-graph-gallery.com/network.html">R</a>, <a
href="https://www.python-graph-gallery.com/network-chart/">Python</a>,
<a href="https://www.react-graph-gallery.com/network-chart">React</a>
and <a href="https://d3-graph-gallery.com/network.html">D3</a> graph
galleries are 4 websites providing hundreds of chart example, always
providing the reproducible code. Click the button below to see how to
build the chart you need with your favorite programing language.</p>
<p>
<a href="https://www.r-graph-gallery.com/network.html" class="btn btn-primary">R
graph gallery</a>
<a href="https://python-graph-gallery.com/network-chart/" class="btn btn-primary">Python
gallery</a>
<a href="https://www.react-graph-gallery.com/network-chart" class="btn btn-primary">React
gallery</a>
<a href="https://d3-graph-gallery.com/network.html" class="btn btn-primary">D3
gallery</a>
</p>
</div>
</div>

          <section
            id="form"
            style="
              margin-top: 70px;
              padding-bottom: 70px;
              padding-top: 70px;
              background-color: #f8f9fa;
            "
          >
            <div class="container">
              <div
                style="
                  display: flex;
                  flex-direction: column;
                  align-items: center;
                "
              >
                <h2 style="font-size: 44px" class="text-center">
                  Dataviz decision tree
                </h2>
                <p
                  class="text-center"
                  style="max-width: 600px; font-size: 18px"
                >
                  <a href="https://www.data-to-viz.com">Data To Viz</a> is a
                  comprehensive <b>classification of chart types</b> organized
                  by data input format. Get a high-resolution version of our
                  decision tree delivered to your inbox now!
                </p>
                <div
                  style="
                    margin-top: -50px;
                    width: 100%;
                    display: flex;
                    justify-content: center;
                  "
                >
                  <script
                    async
                    data-uid="8010f15fd2"
                    src="https://prodigious-trailblazer-3628.ck.page/8010f15fd2/index.js"
                  ></script>
                </div>
                <br />
                <div class="text-center">
                  <img
                    class="img-fluid"
                    src="../img/poster/poster_small.png"
                    alt="High Resolution Poster"
                    style="max-width: 400px"
                  />
                </div>
              </div>
            </div>
          </section>

           &nbsp;
<hr />
<p style="text-align: center;">A work by <a href="https://www.yan-holtz.com/">Yan Holtz</a> for <a href="https://data-to-viz.com">data-to-viz.com</a></p>

<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Add font awesome icons -->
<p style="text-align: center;">
	<a href="https://twitter.com/r_graph_gallery?lang=en" class="fa fa-twitter"></a>
	<a href="https://www.linkedin.com/in/yan-holtz-2477534a/" class="fa fa-linkedin"></a>
	<a href="https://github.com/holtzy/" class="fa fa-github"></a>
</p>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-3"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-79254642-3');
</script>
<script>
var getOutboundLink = function(url) {
	gtag('event', 'click', {
		'event_category': 'outbound',
		'event_label': url,
		'transport_type': 'beacon',
		'event_callback': function(){document.location = url;}
	});
}
</script>

&nbsp;                </div>

    <script>

      // add bootstrap table styles to pandoc tables
      function bootstrapStylePandocTables() {
        $('tr.header').parent('thead').parent('table').addClass('table table-condensed');
      }
      $(document).ready(function () {
        bootstrapStylePandocTables();
      });

          </script>
       </body>
</html>
